home *** CD-ROM | disk | FTP | other *** search
- #define _H_P2PX
- /*==================================================================================
-
- File P2PX.h
- © B.Raoult 1992
-
- mab@ecmwf.co.uk
-
-
- How to write a Print2Pict extension:
- ------------------------------------
-
- A Print2Pict extension is a code resource of type 'P2PX' id = -8192,
- in a file of type 'P2PX' and creator 'P2P '. The code entry point is
- a Pascal function (so extension can be wrote in Pascal or C).
-
- pascal OSErr main(short msg,P2PXPtr arg);
-
- The function is called with two parameters: the first is a function selector,
- the second is a pointer to a parameter block containing various field described
- later. The function must return noErr if everything was OK, or the code
- of any errors.
-
- When the extension is called, the current resource file is set to the
- extension file.
-
- Values of the message parameter:
- ================================
-
- - getFlagsMsg
- -------------
-
- This message is sent before opening the Style or the Job dialogs:
- Print2Pict use the answer to enable or disable some items in the
- dialogs. You must fill the "flags" with the following values:
-
- if ENVIRONMENT_OK is not set, the name of the extension is disabled in the
- popup menu. It cannot be selected by the user. You must clear this bit
- if your extension requires system features that are not available on this
- machine. (Color QuickDraw, ...)
-
-
- if WANT_FILE_NAMES is set, Print2Pict will generate a filename for every
- page printed and pass it to you in the "fsspec" and "script" fields of
- the argument when sending the putPageMsg message. This name either
- automatically generated or was specified by the user according to the
- user choice in the Print2Pict options dialog. Use the "creator" field
- to create the files. If you want only one file name, clear the
- WANT_FILE_NAMES bit once you have received the first putPageMsg message.
-
- if HAS_OWN_PAGE_SIZE is set, Print2Pict will look for a PREC resource
- id = 3 in your resource file to setup the Style dialog. A maximum of
- 5 page sizes can be displayed (the sixth is reserved for the custom
- paper size). When this bit is set, the external cannot be selected
- in the Job dialog, as an other size may have been chosen in the Style
- dialog.
-
- if HAS_OWN_OPTIONS is set, your external must provide a DITL resource
- id = -8192, and ICON resource id = -8192 and optionally a cicn resource
- id = -8192. The ICON (or cicn) is displayed in the options dialog.
- If the user click on it, the DITL is then appended to the dialog. Your
- external must respond to the optOpenMsg, optEventMsg, optItemMsg
- and optDoneMsg messages.
-
- if ONLY_BLACK_WHITE is set, Print2Pict will create black and white picture.
-
- if CAN_PREVIEW is set the user can preview the pages before they are
- disposed. If you provide a resource PREV id = -8192 containing a pascal
- string that will be use to change the title of the disposition button in
- the preview dialog.
-
- if CAN_SPOOL is set, Print2Pict may spool the picture to a file if the memory
- is too low. The spooled field is set, spooledfile contains the filespec of
- the spooled picture (PICT format). [NOT YET IMPLEMENTED]
-
- When entering your routine the "flags" field is set with the DEFAULT_FLAGS values
- (ENVIRONMENT_OK + WANT_FILE_NAMES + CAN_PREVIEW).
-
- The getFlagsMsg message is also sent when the application calls PrOpenDoc,
- before sending the initMsg, to check if the ENVIRONMENT_OK is still set.
-
- Don't use any fields of the argument other than the "flags" field.
-
-
-
- - initMsg
- ---------
-
- The message is sent when the application calls PrOpenDoc.
- If you need some local storage, allocate a handle, and put it
- in the "data" field of the argument.
-
- - endMsg
- --------
- The message is sent when the application calls PrCloseDoc.
- You must free any memory allocated, close any opened file.
-
- Always check the "data" field before calling DisposHandle.
-
-
- - putPageMsg
- ------------
-
- The message is sent when the application calls PrClosePage.
- This is where you must process the picture.
-
- "error" is the last error.
- "page" contains the current page number. (Starting from 1)
- "pict" contains a handle on the picture of the current page.
- "docName" is the name of the printed document (can be empty).
- "appName" is the name of the current application.
-
- If WANT_FILE_NAMES is set in the "flags" field:
- "fsspec" is the file spec where the page is to be saved, and
- "script" the scriptcode to use with FSpCreate.
-
- If CAN_SPOLL is set in the "flags" field, Print2Pict may spool the
- picture to disk if the memory is low. [NOT YET IMPLEMENTED]
- "pict" is the set to NULL, "spooled" is true, and "spoolfile"
- contains the file spec of the file where the picture is spooled
- (PICT format)
-
-
- - optOpenMsg
- ------------
-
- To receive this message the HAS_OWN_OPTIONS bit must be set.
- Print2Pict display the DITL you provide and calls the external.
- You can allocate some private storage in the "data" field.
- You must initialize the dialog items here.
- "dlog" is the dialog containing your items, "skip" is the number
- of items in this dialog belonging to Print2Pict.
-
- - optEventMsg
- -------------
-
- To receive this message the HAS_OWN_OPTIONS bit must be set.
- The external is called from the ModalDialog filter procedure.
-
- "dlog" is the dialog containing your items, "skip" is the number
- of items in this dialog belonging to Print2Pict.
- "event" is the events that triggered the call, "itemHit" is the
- item passed to the filter procedure, "retcode" must be set to
- true if "itemHit" was changed. See InsideMac I page 415 for
- more details about the filter procedure.
-
- - optItemMsg
- ------------
-
- To receive this message the HAS_OWN_OPTIONS bit must be set.
- The external is called with the item returned by ModalDialog.
- You must update the check boxes and the radio buttons.
- "item" is the value return by ModalDialog.
- "dlog" is the dialog containing your items, "skip" is the number
- of items in this dialog belonging to Print2Pict.
- The dialog item "skip" is a static text you can use to display
- any messages.
-
-
- - optDoneMsg
- ------------
-
- To receive this message the HAS_OWN_OPTIONS bit must be set.
- Print2Pict calls the external before removing the DITL from the dialog.
- You must get the new values of the dialog items, and release any allocated
- memory.
- "dlog" is the dialog containing your items, "skip" is the number
- of items in this dialog belonging to Print2Pict.
-
-
- Values of the P2PXPtr parameter:
- ================================
-
- For every calls, a parameter is passed to the extension. All field are read only
- except "flags" and "data".
-
- Print2Pict fills the block with zeros and then sets the fields. So you are sure
- that missing fields are set to zero:
-
- ALWAYS CHECK A POINTER (OR HANDLE) FIELD AGAINST NULL BEFORE DEREFERENCING IT.
-
- This is a description of the field of the parameter block using the format
- - name (type) [list of messages for which the field is valid]
-
- - vers (short) [all]
- --------------------
-
- Print2Pict major version, set to 3 at present.
-
- - port (TPPrPort) [putPageMsg]
- ------------------------------
-
- Current print graph port.
-
- - hPrint (THPrint) [putPageMsg]
- -------------------------------
-
- Current print record.
-
- - page (short) [putPageMsg]
- ---------------------------
-
- Current page number (starting from 1).
-
- - pict (PicHandle) [putPageMsg]
- -------------------------------
-
- Picture of the current page. If NULL, then the picture was spooled (see
- spooled and spoolfile)
-
- - color (Boolean) [putPageMsg]
- ------------------------------
-
- Set to true if the print grafport is the color port.
-
- - flags (long) [all]
- --------------------
-
- Set by the extension. See previous paragraph.
-
- - error (OSErr) [all]
- --------------------
-
- Last error reported by Print2Pict.
-
- - data (Handle) [initMsg,putPageMsg,endMsg]
- [optOpenMsg,optEventMsg,optItemMsg,optDoneMsg if HAS_OWN_OPTIONS]
- ---------------------------------------------------------------------------------
-
- Put here a handle to your private storage. Alocate it when
- you receive initMsg or optOpenMsg, free it when you receive endMsg or optDoneMsg.
-
- - docName (Str255) [initMsg,putPageMsg,endMsg]
- ----------------------------------------------
-
- Name of the printed document.
-
- - appName (Str255) [initMsg,putPageMsg,endMsg]
- ----------------------------------------------
-
- Name of the current application.
-
- - fspec (FSSpec) [putPageMsg if WANT_FILE_NAMES]
- ------------------------------------------------
-
- File spec. where to save the picture to.
-
- - script (ScriptCode) [putPageMsg if WANT_FILE_NAMES]
- -----------------------------------------------------
-
- script code of fspec (needed for FSpCreate).
-
- - creator (OSType) [all]
- ------------------------
-
- creator choosen by the user in the Print2Pict options dialog.
-
- - spooled (Boolean) [putPageMsg if CAN_SPOLL] [NOT YET IMPLEMENTED]
- -------------------------------------------------------------------
-
- true if the picture was spooled.
-
- - spoolfile (FSSpec) [putPageMsg if CAN_SPOLL] [NOT YET IMPLEMENTED]
- --------------------------------------------------------------------
-
- file spec of the spooled picture (PICT file). set if spooled is true.
-
- - dlog (DialogPtr) [optOpenMsg,optEventMsg,optItemMsg,optDoneMsg if HAS_OWN_OPTIONS]
- -------------------------------------------------------------------------------------
-
- Dialog where the your DITL is displayed.
-
- - event (EventRecord*) [optEventMsg if HAS_OWN_OPTIONS]
- -------------------------------------------------------
-
- Event received in ModalDialog filter procedure.
-
- - itemHit (short*) [optEventMsg if HAS_OWN_OPTIONS]
- ---------------------------------------------------
-
- Item received in ModalDialog filter procedure.
-
- - retcode (Boolean) [optEventMsg if HAS_OWN_OPTIONS]
- ----------------------------------------------------
-
- Return code of ModalDialog filter procedure.
-
- - skip (short) [optOpenMsg,optEventMsg,optItemMsg,optDoneMsg if HAS_OWN_OPTIONS]
- --------------------------------------------------------------------------------
-
- Number of items belonging to Print2Pict in the dialog.
-
- - item (short) [optItemMsg if HAS_OWN_OPTIONS]
- ----------------------------------------------
-
- Item number returned by ModalDialog.
-
- Help:
- =====
-
- To provide somme help to the user, add a TEXT resource id = -8192 and
- an optional styl resource, same id. The text will be displayed in the
- Help window.
-
- Ideas:
- ======
-
- Here are some ideas of extensions:
- - Print to Movie (QuickTime) each page is a frame.
- - HyperPrint (HyperCard) each page is a card. Has its own paper format (the
- size of a card.
- - Print to RTF, Print to Word, ... all text formats.
- - Print to PCX, GIF, all PC stuff, ....
- - Print to X, XWindows Pixmaps.
-
- You are welcome to send me any extensions you write, so I can add them to
- the next releases of Print2Pict.
-
-
- ==================================================================================*/
-
- #include <PrintTraps.h>
-
-
- /*============================ Messages =====================================*/
-
- /* Get flags */
-
- #define getFlagsMsg 1
-
-
- /* Printing ... */
-
- #define initMsg 2
- #define endMsg 3
- #define putPageMsg 4
-
- /* Options */
-
- #define optOpenMsg 5
- #define optEventMsg 6
- #define optItemMsg 7
- #define optDoneMsg 8
-
- /*=============================== Flags =====================================*/
-
-
- #define ENVIRONMENT_OK 1L /* Set if machine OK (i.e. has color QD,...) */
- #define WANT_FILE_NAMES 2L /* If code resource need file names */
- #define HAS_OWN_PAGE_SIZE 4L /* If the code has its own page size */
- #define CAN_PREVIEW 8L /* Pages can be previewed before disposed */
- #define HAS_OWN_OPTIONS 16L /* If code has own options dialog */
- #define ONLY_BLACK_WHITE 32L /* No color pictures */
- #define CAN_SPOOL 64L /* Can use spooled pictures */
-
- #define DEFAULT_FLAGS (ENVIRONMENT_OK+WANT_FILE_NAMES+CAN_PREVIEW)
-
- /*============================= Parameter block =============================*/
-
- typedef struct {
-
- short vers; /* Print2Pict major version (3 now) */
-
- TPPrPort port; /* Print graphport */
-
- THPrint hPrint; /* Print record */
- short page; /* Current page */
- PicHandle pict; /* Content of page */
- Boolean color; /* The printport is a color port */
-
- long flags; /* Code flags */
- Handle data; /* Free to use */
-
- OSErr error; /* Last error code */
-
- Str255 docName; /* Name of printed document */
- Str255 appName; /* Name of current application */
-
- FSSpec fspec; /* File spec if WANT_FILE_NAMES */
- ScriptCode script; /* Script code if WANT_FILE_NAMES */
- OSType creator; /* user chosen creator */
-
- Boolean spooled; /* Picture was spooled */
- FSSpec spoolfile; /* Spolled picture */
-
- /* Stuff for options dialog */
-
- DialogPtr dlog; /* The options dialog */
-
- EventRecord *event; /* Event received in ModalDialog filter proc */
- short *itemHit; /* Item received in ModalDialog filter proc */
- Boolean retcode; /* Retcode of ModalDialog filter proc */
-
- short skip; /* Number of items belonging to Print2Pict */
- short item; /* Item number returned by modal dialog */
-
- } P2PXRec, *P2PXPtr;
-